///**
// * 进行格式转换
// */
//function loginTimeFormatter(value) {
//	return new Date(value).Format("yyyy-MM-dd HH:mm:ss");
//}
//function registerTimeFormatter(value) {
//	return new Date(value).Format("yyyy-MM-dd");
//}
//function nameFormatter(value, row) {
//	return '<a href="javascript:void(0)" onclick="layer_show(\'' + row.userName + '\',\'' + baselocation + '/administrator/list/' + row.userId + '\',\'500\',\'425\')">' + value + '</a>';
//}
//function statusFormatter(value) {
//	if (value == 1) {
//		return '<span class="label label-primary">正常</span>'
//	} else if (value == 0) {
//		return '<span class="label label-danger">冻结</span>'
//	}
//}
//格式转换
function topFormatter(value){
	if(value==1){
		return '<span class="label label-primary">置顶</span>'
	}else{
		return '<span class="label label-danger">默认</span>'
	}
	
}
function navFormatter(value){
	if(value==1){
		return '<span class="label label-primary">显示</span>'
	}else{
		return '<span class="label label-danger">隐藏</span>'
	}
	
}
function HotFormatter(value){
	if(value==1){
		return '<span class="label label-primary">热门</span>'
	}else{
		return '<span class="label label-danger">默认</span>'
	}
	
}
function ShelveFormatter(value){
	if(value==1){
		return '<span class="label label-primary">上架</span>'
	}else{
		return '<span class="label label-danger">已下架</span>'
	}
	
}
function labelFormatter(value){
	
	if(value==1){
		return '<span class="label label-danger">热销</span>'
	}else if(value==2){
		return '<span class="label label-info">新品</span>'
	}else if(value==3){
		return '<span class="label label-success">现货</span>'
	}else{
		return '<span class="label label-primary">有赠品</span>'
	}
}
function imgFormatter(value) {
	if(value!=null){
		return '<img style="height: 90px;width: 90px" alt="图片" src="/static/'+value+'">'
	}else{
		return '<span class="label label-danger">暂无图片</span>'
	}
}
function actionFormatter(value, row, index) {
	if (row.showInShelve == 1) {
		return [
			'<a class="down m-r-sm text-info" href="javascript:void(0)" title="下架">',
			'<i class="glyphicon glyphicon-pause"></i>',
			'</a>',
			'<a class="edit m-r-sm text-warning" href="javascript:void(0)" title="编辑">',
			'<i class="glyphicon glyphicon-edit"></i>',
			'</a>',
			'<a class="remove m-r-sm text-danger" href="javascript:void(0)" title="删除">',
			'<i class="glyphicon glyphicon-remove"></i>',
			'</a>',
		].join('');
	} else {
		return [
			'<a class="up m-r-sm text-info" href="javascript:void(0)" title="上架">',
			'<i class="glyphicon glyphicon-play"></i>',
			'</a>',
			'<a class="edit m-r-sm text-warning" href="javascript:void(0)" title="编辑">',
			'<i class="glyphicon glyphicon-edit"></i>',
			'</a>',
			'<a class="remove m-r-sm text-danger" href="javascript:void(0)" title="删除">',
			'<i class="glyphicon glyphicon-remove"></i>',
			'</a>',
		].join('');
	}
}

window.actionEvents = {
		'click .down' : function(e, value, row, index) {
			showInShelve_down(index, row.productId);
		},
		'click .up' : function(e, value, row, index) {
			showInShelve_up(index, row.productId);
		},
		'click .edit' : function(e, value, row, index) {
			layer_show(row.name,baselocation + '/product/list/' + row.productNumber + '/edit', 800, 550)
		},
		'click .remove' : function(e, value, row, index) {
			product_delete(index, row.productId);
		}
	};


/**
 * 商品下架
 * */
function showInShelve_down(index,value) {
	layer.confirm('确认要下架该商品吗？', {
		btn : [ '确定', '取消' ] //按钮
	}, function() {
		$.ajax({
			dataType : 'json',
			type : 'put',
			url : baselocation + '/product/list/' + value + '/audit',
			success : function(result) {
				if (result.code == 1) {
					$('#table').bootstrapTable('updateRow', {
						index : index,
						row : {
							status : 0,
						}
					});
					layer.msg('该商品下架成功!', {
						icon : 5,
						time : 1000
					});
					window.location.href=baselocation + '/product/list/view';
				} else {
					layer.alert(result.message, {
						icon : 2
					});
				}
			}
		})
	});
	
}
/**
 * 商品上架
 * */
function showInShelve_up(index,value) {
	layer.confirm('确认要上架该商品吗？', {
		btn : [ '确定', '取消' ] //按钮
	}, function() {
		$.ajax({
			dataType : 'json',
			type : 'put',
			url : baselocation + '/product/list/' + value + '/audit',
			success : function(result) {
				if (result.code == 1) {
					$('#table').bootstrapTable('updateRow', {
						index : index,
						row : {
							status : 1,
						}
					});
					layer.msg('该商品上架成功!', {
						icon : 6,
						time : 1000
					});
					window.location.href=baselocation + '/product/list/view';
				} else {
					layer.alert(result.message, {
						icon : 2
					});
				}
			}
		})
	});
}
/**
 * 删除商品
 * */
function product_delete(index,value) {
	layer.confirm('确认要删除该商品吗？', {
		btn : [ '确定', '取消' ] //按钮 
	}, function() {
		$.ajax({
			type : 'delete',
			dataType : 'json',
			url : baselocation + '/product/list/' + value,
			success : function(result) {
				if (result.code == 1) {
					$('#table').bootstrapTable('hideRow', {
						index : index
					});
					layer.msg('该商品删除成功!', {
						icon : 1,
						time : 1000
					});
				} else {
					layer.alert(result.message, {
						icon : 2
					});
				}
			}
		})
	});
}

